package main

import (
	"fmt"
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

const AppConfigPath = "config/app.yaml"

type AppConfig struct {
	SleepMilliSecond int64 `yaml:"sleep-milli-second"`
	InsertSql string `yaml:"insert-sql"`
	InsertValueTypes string `yaml:"insert-value-types"`
	InsertValues string `yaml:"insert-values"`
	ThreadCount int `yaml:"thread-count"`
	BatchCount int `yaml:"batch-count"`
	PrintPeriod int64 `yaml:"print-period"`
}
/**
* 读取应用配置
 */
func (appConfig *AppConfig) getConfig() *AppConfig {
	yamlFile, err := ioutil.ReadFile(AppConfigPath)
	if err != nil {
		fmt.Println(err.Error())
	}
	err = yaml.Unmarshal(yamlFile, appConfig)
	if err != nil {
		fmt.Println(err.Error())
	}
	if appConfig.SleepMilliSecond < 50 {
		appConfig.SleepMilliSecond = 50
	}
	if appConfig.ThreadCount < 2 {
		appConfig.ThreadCount = 2
	}
	if appConfig.BatchCount < 1 {
		appConfig.BatchCount = 1
	}
	if appConfig.PrintPeriod < 100 {
		appConfig.PrintPeriod = 100
	}
	return appConfig
}